package cn.technology.forum.config;

import cn.technology.forum.im.handler.MsgHandlerFactory;
import cn.technology.forum.im.server.ImServerStarter;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;

import java.io.IOException;

/**
 * @author moguai
 * @version 1.0
 * @date 2022/4/14 0:45
 */
@Slf4j
@Data
@Configuration
@Order(value = Integer.MAX_VALUE)
public class ImServerAutoConfig {
    @Value("${im.server.port}")
    private Integer imPort;
    @Bean
    public ImServerStarter imServerStarter() {
        try {
            ImServerStarter imServerStarter = new ImServerStarter(imPort);
            imServerStarter.start();
            //初始化消息处理器工程
            MsgHandlerFactory.init();
            log.info("---------> im server started !");
            return imServerStarter;
        } catch (IOException e) {
            log.error("im server 启动失败~~", e);
        }
        return null;
    }
}
